#include "Destroyable.h"

mtBEGIN(DestroyableDef)
	mtCONSTRUCTOR();
mtEND

mtBEGIN(Destroyable)
	mtBASE(ECS::Component);
	mtCONSTRUCTOR();
	mtMETHOD(initWith);
	mtSIGNAL(eventDestroyed);
mtEND

Destroyable::Destroyable()
{
	memset(_attributes, 0, sizeof(UnitAttribute) * UnitAttribute::AttributeCount);
	memset(_bonuses, 0, sizeof(UnitAttribute) * UnitAttribute::AttributeCount);
}

bool Destroyable::initWith(DestroyableDef* def)
{
	memcpy(_attributes, def->attributes, sizeof(UnitAttribute) * UnitAttribute::AttributeCount);
	return true;
}

int Destroyable::getAttribute(UnitAttribute type) const
{
	return _attributes[type];
}

void Destroyable::setAttribute(UnitAttribute type, int value)
{
	_attributes[type] = value;
}

int Destroyable::getAttributeWithBonus(UnitAttribute type) const
{
	return _attributes[type] + _bonuses[type];
}